<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
      <!--BEGIN TITLE & BREADCRUMB PAGE-->
      <div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
          <div class="page-header pull-left">
              <div class="page-title">数据导出</div>
          </div>
          <ol class="breadcrumb page-breadcrumb pull-left">
              <li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li>数据处理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li class="active">数据导出</li>
          </ol>
           
          <div class="clearfix"></div>
      </div>
      <!--END TITLE & BREADCRUMB PAGE-->
      <!--BEGIN CONTENT-->
      <div class="page-content">
      
      <div class="row mbl">
           <div class="col-lg-6">
               <div class="input-group input-group-sm mbs"><span class="input-group-btn">
               	  <select id="queryParams" class="btn btn-danger dropdown-toggle" style="width :130px;">
                    <option value="name">数据导出名称</option>
                    <option value="description">数据导出描述</option>
                    
                  <!--   <option value="fieldType">数据类型</option>--> 
                    </select>
                   </span>
                   <input type="text" id="text"  placeholder="请输入关键词..." class="form-control" /><span class="input-group-btn"><button type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle" onclick="list1()">搜索</button></span>
               </div>
           </div>
           <div class="col-lg-6">
           <div class="tb-group-actions pull-right"><span>当前共<label id="pageSize"></label>条记录:</span>
                   <select id="pageNumber" class="table-group-action-input form-control input-inline input-small input-sm mlm" onchange="get()">
                       <option value="5">5</option>
                       <option value="10" >10</option>
                       <option value="15" selected>15</option>
                       <option value="25">25</option>
                       <option value="50">50</option>
                   </select>&nbsp;
                   
               <div class="tb-group-actions pull-right">
                <button class="btn btn-sm btn-primary" onclick="importfrom('0')">新增
                   </button>
                   </div>
               </div>
           </div>
       </div>
      
      <table class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
            <thead>
                <tr>
                    
                    <th >序号</th>
                    <th >数据导出名称</th>
                    <th >数据导出描述</th>
                    <th >数据源名称</th>
                    <th>知识库名称</th>
                    <th >最近导出时间</th>
                
                    <th >可操作</th>
                </tr>
            </thead>
            <tbody id="newspaperls"></tbody>
        </table>
<div id="dataNull" class="panel-body"
				style="height: 90px; line-height: 50px;" align="center">
				<span class='subtitle' style="font-size: 15px;">数据为空!</span>
		</div>
        <div id="page1" style="text-align: center; margin-top: 20px;"></div>
    </div>
                     
    <!--END CONTENT-->
    </div>

  <form action="./DataExportdownload.do" method="post" name="aa" target="_blank">
<input id="downloadid" name="downloadid" value="" type="hidden"/>
</form>
<?} ?>
<script>
 var cur;
$(function(){
    cur=1;
	list1(cur);
});
function get()
{
  list1(cur);
}
function list1(curr) {
				$.getJSON("./KnowledgeExportList.do",
								{page : curr || 1,
									queryParams : $("#queryParams").val(),
									text : $("#text").val(),
									pageNumber : $("#pageNumber").val()
								},
								function(res) {
									//此处仅仅是为了演示变化的内容
									//alert(JSON.stringify(res));
									var str = "";
									 if(res.listsize>0){
										$("#dataNull").hide();
									}else{
										$("#dataNull").show();
									}
									$("#newspaperls").html("");
									for ( var i = 0; i < res.listsize; i++) {
										var dataSourcename='';
										
										for ( var j = 0; j < res.rdataSource.length; j++) {
											if(res.rdataSource[j].id == res.result[i].dataSourceId && dataSourcename == ''){
												dataSourcename = res.rdataSource[j].name;
											}
										}
										/* if (res.result[i].dataSource == null) {
											dataSourcename = " ";
										} else {
											dataSourcename = res.result[i].dataSource.name
										} */
										var classesname ='';
										for ( var j = 0; j < res.rclasses.length; j++) {
											if(res.rclasses[j].id == res.result[i].classesId && classesname == '' ){
												classesname = res.rclasses[j].nameZh;
											}
										}
										/* if (res.result[i].classes == null) {
											classesname = " ";
										} else {
											classesname = res.result[i].classes.nameZh;
										} */

										str += "<tr><td align=\"center\"> "
												+ (i + 1)
												+ "</td><td> <label >"
												+ res.result[i].name
												+ "</label></td><td><label >"
												+ res.result[i].description
												+ "</label></td><td><label >"
												+ dataSourcename
												+ "</label></td><td><label >"
												+ classesname
												+ "</label></td><td><label >"
												+ res.result[i].createTime
												+ "</label></td><td>"
												+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"download('"
												+ res.result[i].id
												+ "')\">"
												+ "下载"
												+ "</button>"
												+ "         <button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"del('"
												+ res.result[i].id
												+ "')\">"
												+ "删除"
												+ "</button>"
												+ "</td></tr>";
									}
									$("#newspaperls").append(str);
                                  document.getElementById('pageSize').innerHTML=res.listsize;
                              
									laypage({
										cont : document.getElementById('page1'), //容器。值支持id名、原生dom对象，jquery对象,
										pages : res.pageSize, //总页数
										skip : true, //是否开启跳页
										skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
										curr : curr || 1,
										last: res.pageSize,
										groups : 6,//连续显示分页数
										jump : function(obj, first) { //触发分页后的回调
											if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
												list1(obj.curr);
												var curr = obj.curr;
												curr = obj.curr;
											}
										}
									});
								});
								}


		function download() {
			$.ajax({
				type : "post",
				url : "./DataImportTempletdownload.do",
				data : {
				},
				dataType : "json",
				success : function(data) {
					list1(curr);
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}	
  
		function importfrom() {
				layer.open({
				    type : 2,
				     icon: 1,
                    skin: 'layer-ext-moon',
					area : [ '600px', '550px' ],
					fix : false, //不固定
					scrollbar : false,
					shadeClose : true,
					move : false,
					skin : 'layui-layer-rim', //加上边框
					btn : [ '保存 ', '关闭' ],
					content :[ "data-export-from.html",'no'],
					yes: function(index,layer){
    	                  var iframeWin = parent.window[layer.find('iframe')[0]['name']];
    	                  iframeWin.save();
    	              },
					cancel : function(index) {
					}
				});
			}
	
	function download(kk){
		$("#downloadid").val(kk);
		document.forms['aa'].submit();
	}

	function del(id) {
				if (confirm("是否确认删除！！")) {
					$.ajax({
						type : "post",
						url : "./KnowledgeExportdel.do",
						data : {
							"id" : id
						},
						dataType : "json",
						success : function(data) {
							layer.msg("删除成功");
							get();
						},
						error : function(data) {
							alert("请求失败");
						}
					});
				}

			}
</script>